<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>会员列表-WeAdmin 1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/weadmin.css">
    <script src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/admin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <link rel="stylesheet" href="../../static/css/app.css">
    <link rel="stylesheet" href="../../static/css/survey.css">
    <link rel="stylesheet" href="../../static/css/index.css">
    <![endif]-->


    <style type="text/css">
        table{
            table-layout:fixed;/* 只有定义了表格的布局算法为fixed，下面td的定义才能起作用。 */
        }
        th{
            width:100%;
            word-break:keep-all;/* 不换行 */
            white-space:nowrap;/* 不换行 */
            overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */
            text-overflow:ellipsis;/* 当对象内文本溢出时显示省略标记(...) ；需与overflow:hidden;一起使用*/
        }
    </style>

</head>

<body style="background-color: #f0f0f0">

<div class="weadmin-body" >
    <div class="block-survey">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" >音频名称</label>
                    <div class="layui-input-inline">
                        <input type="tel" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">上架时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="date" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" lay-key="1">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-inline">
                        <select name="quiz">
                            <option value="ss">全部状态</option>
                            <option value="sss">上架</option>
                            <option value="ssss">下架</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-normal">搜索</button>
                    <input type="button" class="layui-btn layui-btn-normal" onclick="editCourseList()" value="新建">
                </div>
            </div>
        </form>
    </div>

    <table class="layui-table table" id="tableList">
        <colgroup>
            <col name="el-table_1_column_21" width="10%">
            <col name="el-table_1_column_21" width="10%">
            <col name="el-table_1_column_21" width="13%">
            <col name="el-table_1_column_21" width="7%">
            <col name="el-table_1_column_21" width="10%">
            <col name="el-table_1_column_21" width="7%">
            <col name="el-table_1_column_21" width="10%">
        </colgroup>
        <thead>
        <tr>
            <th>音频名称</th>
            <th>音频简介</th>
            <th>音频</th>
            <th>试听秒数</th>
            <th>音频封面</th>
            <th>音频排序</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
    <div style="text-align: center" id="foot"></div>
</div>


<script type="text/javascript"  src="../../static/js/jquery.min.js" ></script>

<script src="../../static/js/republic.js" charset="utf-8"></script>
<script>
    var jsessionid= localStorage.getItem("jsessionid")

    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#date', //指定元素
            theme: '#BDBDBD',
        });
    });

    var queryVariable;
    $(function () {
         queryVariable = getQueryVariable('id');
        $.ajax({
            type: "GET",
            headers: {
                "Authorization":"Bearer "+ localStorage.getItem("token")
            },
            url: serverUrl+'/api/KnowledgeCourse/getList/'+queryVariable +';jsessionid='+jsessionid,
            xhrFields: {
                withCredentials : true
            },
            success: function (r) {
                if (r.code == 0) {
                    $.each(r.data.results,function (key,value) {
                        $("#tableList tbody").append("<tr>" +
                            "<th>"+value.name+"</th>" +
                            "<th  class='th'>"+value.briefIntroduction+"</th>" +
                            "<th><audio src="+value.radioUrl+" controls=\"controls\"></audio></th>" +
                            "<th>"+value.seconds+"</th>" +
                            "<th><img src="+value.imageUrl+"  /></th>" +
                            "<th>"+value.orderNum+"</th>" +
                            "<th><span  onclick='editCourseList("+value.id+")' >编辑</span>" +
                            " <span  onclick='deleteCoursrList("+value.id+")'>删除</span></th></tr>");
                    });
                    layui.use('laypage', function(){
                        var laypage = layui.laypage;
                        laypage.render({
                            elem: 'foot',
                            count: r.data.totalRecord,
                            jump: function(obj, first){
                                //obj包含了当前分页的所有参数，比如：
                                //首次不执行
                                if(!first){
                                    $.ajax({
                                        type: "GET",
                                        headers: {
                                            "Authorization":"Bearer "+ localStorage.getItem("token")
                                        },
                                        // url: serverUrl+'/api/KnowledgeCourse/getList/'+queryVariable,
                                        url: serverUrl+'/api/KnowledgeCourse/getList/'+queryVariable+"/"+obj.curr +';jsessionid='+jsessionid,
                                        xhrFields: {
                                            withCredentials : true
                                        },

                                        success: function (r) {
                                            if (r.code == 0){
                                                $("#tableList tbody").html("");
                                                $.each(r.data.results,function (key,value) {
                                                    $("#tableList tbody").append("<tr>" +
                                                        "<th>"+value.name+"</th>" +
                                                        "<th  class='th'>"+value.briefIntroduction+"</th>" +
                                                        "<th><audio src="+value.radioUrl+" controls=\"controls\"></audio></th>" +
                                                        "<th>"+value.seconds+"</th>" +
                                                        "<th><img src="+value.imageUrl+"  /></th>" +
                                                        "<th>"+value.orderNum+"</th>" +
                                                        "<th><input type='button' value='编辑' onclick='editCourseList("+value.id+")' ><input type='button' value='删除' onclick='deleteCoursrList("+value.id+")'></th></tr>");
                                                });
                                            }
                                        }
                                    })
                                }
                            }
                        });
                    });
                } else if(r.code = 2 ){
                    document.location.href = "./login.html";
                }else {
                    // alert("失败")
                }
            },
        })

    });


   function editCourseList(id){
       if (!id){
           document.location.href = "./editorRadioList.html?courseId="+queryVariable;
       }else {
           document.location.href = "./editorRadioList.html?id="+id;

       }
    }


    function deleteCoursrList(id){
       // alert("删除按钮111")
       // /KnowledgeCourseAction/deleteCourseList/
        // document.location.href = "./editorRadio.html/"+id;


        layer.open({
            title: ''
            ,content: '确定删除吗?'
            ,btn:[' 确定','取消'],
            yes: function(index, layero){
                $.ajax({
                    type: "GET",
                    url: serverUrl+'/KnowledgeCourseAction/deleteCourseList/'+id +';jsessionid='+jsessionid,
                    xhrFields: {
                        withCredentials : true
                    },
                    success: function (r) {
                        layer.open({
                            // title: r.msg
                            content: r.msg
                            ,btn:[' 确定','取消'],
                            btn1: function () {
                                window.location.reload();
                            },
                            btn2: function () {
                                window.location.reload();
                            }
                        });
                    },
                    fail : function () {
                        layer.msg("请求错误")
                    }
                });
                layer.close(index);
            },
            btn2: function(index, layero){

            },
        });
    }







</script>
</body>

</html>